package com.icloud.system.boot.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.icloud.common.web.util.ObjectUtil;
import com.icloud.system.api.dto.SaveAdminOperationLogDto;
import com.icloud.system.boot.mapper.AdminOperationLogMapper;
import com.icloud.system.boot.model.AdminOperationLog;
import com.icloud.system.boot.query.OperationLogQuery;
import com.icloud.system.boot.service.AdminOperationLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;


/**
 * 操作日志service实现类
 */
@Service
public class AdminOperationLogServiceImpl extends ServiceImpl<AdminOperationLogMapper, AdminOperationLog> implements AdminOperationLogService {

    /**
     * 添加后台账号操作日志
     */
    @Override
    public void addAdminOperationLog(SaveAdminOperationLogDto dto) {
        AdminOperationLog adminOperationLog = new AdminOperationLog();
        BeanUtil.copyProperties(dto, adminOperationLog, ObjectUtil.getNullField(dto));
        save(adminOperationLog);
    }


    /**
     * 分页查询
     * @param query
     * @return
     */
    @Override
    public IPage<AdminOperationLog> page(OperationLogQuery query) {
        return page(new Page<>(query.getCurrent(),query.getPageSize()),
                new LambdaQueryWrapper<AdminOperationLog>()
                        .like(StringUtils.isNoneBlank(query.getUsername()), AdminOperationLog::getUsername,query.getUsername())
                        .like(StringUtils.isNoneBlank(query.getRequestPath()), AdminOperationLog::getRequestPath,query.getRequestPath()));
    }
}
